package com.example.lxy.controller;

import com.alibaba.fastjson.JSON;
import com.example.lxy.pojo.watertable;
import com.example.lxy.service.WaterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
@ResponseBody
@Api(value = "水费管理",tags = "水费接口模块")
public class WaterController {
    @Autowired
    private WaterService waterService;

    @CrossOrigin
    @PostMapping(value = "/api/waterlist")
    @ApiOperation(value = "查询水费",notes = "查询水费表中的所有")
    public String list() {
        HashMap<String, Object> map = new HashMap<>();
        List<watertable> list = waterService.list();
        if (list!=null) {
            map.put("flag",200);
            map.put("list",list);
        } else {
            map.put("flag",400);
        }
        String s = JSON.toJSONString(map);
        return s;
    }
}
